/*
* @Author: Adolphus.Yao
* @Date:   2019-09-11 19:47:23
* @Last Modified by:   Adolphus.Yao
* @Last Modified time: 2019-09-11 20:07:08
*/
package main

import (
    "fmt"
    "strconv"
)

func toInt32(v interface{}) int32 {
    switch v.(type) {
    case int32:
        return v.(int32)
    case float64:
        return int32(v.(float64))
    case string:
        t, err := strconv.ParseFloat(v.(string), 64)
        if nil != err {
            panic(err)
        }
        return int32(t)
    }
    return 0
}

func main() {
    var t interface{}
    var int32t int32 = 123
    var float64t float64 = 123.23
    var str string = "12.354"
    t = int32t
    fmt.Printf("1: %d\n", toInt32(t))
    t = float64t
    fmt.Printf("2: %d\n", toInt32(t))
    t = str
    fmt.Printf("3: %d\n", toInt32(t))
}
